package com.gmt.service.impl;

import com.gmt.service.IUserService;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: UserService, v 1.0 2020/11/12 19:09 ZhiYong Exp $
 */
@Service
public class UserService implements IUserService {

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        // 模拟数据库操作 根据账号查询
        String password = "$2a$10$/VrFoBbdKnRr/fT7M38KwOhYvlBDN4cFNfTnCbZxcGBjxOfNDuFUO";
        // 假设查询出来的用户的角色
        List<SimpleGrantedAuthority> list = new ArrayList<>();
        list.add(new SimpleGrantedAuthority("roleA"));
        UserDetails userDetails = new User(s,password,list);
        return userDetails;
    }
}
